<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
    <head>
        <title>增加设备</title>
    </head>
    <body>
    <div class="loading"></div>
    <!-- header -->
    <header>
        <a href="javascript:history.go(-1);" class="top_fh">增加设备</a>
    </header>
    <!-- header end -->

    <div class="page">
        <div class="homecdbj_inner">
            <div class="bangding">
                <ul>
                    <form id="addform">
                    <li>
                        <p><span>设备名称</span>
                            <input type="text" name="devicename" placeholder="需填写" />
                        </p>
                    </li>
                    <li class="deviceType">
                        <p><span>设备类型</span>
                            <input type="text" placeholder="请选择"/>
                            <input type="hidden" name="devicetypeid"/>
                        </p>
                    </li>
                    <li>
                        <p><span>礼品库存</span>
                            <input type="text" name="addgift" placeholder="需填写"/>
                        </p>
                    </li>
                    <li style="padding:0 0.7rem;">
                        <select name="placeid">
                            <option selected="selected">场地归属</option>
                            <c:forEach items="${placeList}" var="place">
                                <option value="${place.placeid}">${place.address}</option>
                            </c:forEach>
                        </select>
                    </li>
                    <li><p><span>设备简码</span><i>${device.deviceshortcode}</i></p></li>
                    <li><p><span>唯一码</span><i>${device.imme}</i></p></li>
                        <input type="hidden" name="deviceid" value="${device.deviceid}" />
                    <li class="taocanSet">
                        <p><span>套餐设置</span></p>
                        <ul>
                            <c:forEach items="${discountList}" var="discount">
                                <li>
                                    ${discount.discountname}
                                    <input type="hidden" name="discountIds" disabled="disabled" value="${discount.discountid}" />
                                </li>
                            </c:forEach>
                        </ul>
                    </li>

                    </form>
                </ul>
                <div class="tcse_button"><a href="JavaScript:;" style="border-radius:3px;" id="addSubBtn">添加</a></div>
            </div>
        </div>
    </div>

    <!-- 弹窗 -->
    <div class="tanc_tjglpop ty_pop tanc_deviceTypepop">
        <div class="popbg"></div>
        <div class="deviceList">
            <p>设备类型</p>
            <c:forEach items="${deviceTypeList}" var="deviceType" varStatus="status">
                <div>
                    <div>
                        <span>${deviceType.dtname}</span>
                        <input type="hidden" value="${deviceType.devicetypeid}"/>
                        <div>
                            <div></div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>

    <script type="application/javascript">
        function View(){
            var that = this;

            that.events = [
                { sel : '#addSubBtn', act : 'click', func : 'addSub' }
            ];

            that.addSub = function(){
                $.ajax({
                    url:'${basePath}wechat/operate/device/add',
                    type : 'POST',
                    data : $("#addform").serialize(),
                    error: function (response) {
                        ViewHelper.func.ajaxWechatErrorMessage(response);
                    },
                    success: function (ret) {
                        if(ret.result) {
                            window.location = "${basePath}wechat/operate/device/listView";
                        }else{
                            alert(ret.info);
                        }
                    }
                });
            };

            EventHandler.call(that, that.events);

            return that;
        }

        var view;

        $(function(){
            inherit(View, EventHandler);
            view = new View();
        });
    </script>

</body>
</html>